
<?php
function test_input($data)
{
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
} 

$domain=test_input($_POST["domain"]);
if (empty($domain)) {
	die("域名不能为空");
}
$CP=test_input($_POST["CP"]);
if (empty($CP)) {
	die("CP不能为空");
}
$mon=test_input($_POST["mon"]);

echo "域名：".$domain."\n";
echo "CP：".$CP."\n";
echo "监控状态：".$mon."\n";
header("Content-type: text/html; charset=utf-8");
$con = mysql_connect("113.215.1.161","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//code
mysql_select_db("mydb", $con);//选库
mysql_query("set names 'utf8'");
$res=mysql_query("SELECT * FROM CDN_domainTab WHERE Domain='$domain'");
if (mysql_num_rows($res)) 
{
	echo "该域名已存在\n";
}
else
{
	mysql_query("INSERT INTO CDN_domainTab (Domain,CP, mon) VALUES ('$domain','$CP','$mon')");//插入
	echo "写入完成！\n";
	$res=mysql_query("SELECT * FROM CDN_domainTab WHERE Domain='$domain'");#再次查询
	$row = mysql_fetch_array($res, MYSQL_ASSOC);
	echo "域名：".$row['Domain']."监控状态为：".$row['mon'];
	mysql_close($con);
}

?>
